import React, { useState, useEffect } from 'react'
import { View, Text, } from '@tarojs/components';
import Router from '@/utils/router'
import Taro, { getCurrentInstance, useReachBottom, usePullDownRefresh } from '@tarojs/taro'
import { fetchListUserHelpQaMessage, fakeReadHelpQaMessage } from '@/server/shop'
import Empty from '@/components/Empty'
const AllQa = (props) => {
    const { InteractionConponents } = props
    const [page, setPage] = useState({
        page: 1,
        limit: 20,
    })
    const [list, setList] = useState([])
    const fetchData = () => {
        fetchListUserHelpQaMessage({
            ...page,
        }).then(val => {
            const { userHelpQaMessageList = [] } = val
            setList(userHelpQaMessageList)
            if (page.page == 1) {
                fakeReadHelpQaMessage()
            }
        }).finally(() => {
            Taro.stopPullDownRefresh();
        });
    }
    useEffect(() => {
        fetchData()
    }, [page])


    useEffect(() => {
        fetchData()
    }, [page])
    useReachBottom(() => {
        setPage({
            ...page,
            page: page.page + 1
        })
    })
    usePullDownRefresh(() => {
        setPage(() => {
            setList([])
            return {
                ...page,
                page: 1,

            }
        })
    })

    return <Empty list={list}>
        <View>
            {list.map((item, index) => {
                return <InteractionConponents data={item} key={index}></InteractionConponents>
            })}
        </View>

    </Empty>
}
export default AllQa
